import { requestClient } from '#/api/request';

export namespace TableApi {
  export interface RawTableData {
    columns: string[];
    rows: Array<Record<string, string>>;
  }

  export interface CreateTableDTO {
    userId: string;
    tableName: string;
    tableType: string;
    catalog: string;
    data: RawTableData;
  }
}
const getTableFileData = (fileId: string) => {
  return requestClient.get(`/dsc-systemMS/dsc-table/getDscTable/${fileId}`);
};

const addTableFile = (createTableDTO: TableApi.CreateTableDTO) => {
  return requestClient.post(`/dsc-systemMS/dsc-table/add`, createTableDTO);
};

const updateTableFile = (fileId: string, data: TableApi.CreateTableDTO) => {
  return requestClient.put(`dsc-systemMS/dsc-table/update/${fileId}`, data);
};

const getTableName = (fileId: string) => {
  return requestClient.get(`/dsc-systemMS/dsc-table/getDscTableName/${fileId}`);
};

export default {
  getTableFileData,
  addTableFile,
  updateTableFile,
  getTableName,
};
